package com.my.geojson.test.wfs.xmlGenerate.impl;

import cn.hutool.core.date.DateUtil;
import com.my.geojson.test.wfs.xmlGenerate.WFSTXmlGenerate;
import org.dom4j.Document;

import java.util.HashMap;
import java.util.Map;

/**
 * 插入加修改一个事务操作实现类
 * @author qinlei
 * @description todo
 * @date 2021/10/25 11:33
 */
public class InsertUpdateWfsXmlGenerate extends WFSTXmlGenerate {

    public InsertUpdateWfsXmlGenerate() {
        super();
    }

    @Override
    public Document createXml(String businessId,String username,String typeName,String wfsPath, Map<String, Object> variables, Map<String, Object> params) {
        Map<String, Object> vars = new HashMap<>();
        vars.put("isvalid","0");
        vars.put("uploader",username);
        vars.put("uploadtime", DateUtil.date());
        createUpdateNode(this.getDocument().getRootElement(),typeName,vars,params);
        createGeneralParams(variables,"isvalid","1");
        createGeneralParams(variables,"surveyor",username);
        createGeneralParams(variables,"surveydate", DateUtil.formatDate(DateUtil.date()));
        createGeneralParams(variables,"index_id",businessId);
        createInsertNode(wfsPath,this.getDocument().getRootElement(),typeName,variables);
        return this.getDocument();
    }

    private void createGeneralParams(Map<String, Object> variables,String key,Object param){
        Map<String, Object> map = new HashMap<>();
        map.put("type","general");
        map.put("value",param);
        variables.put(key,map);
    }
}

